const Koa = require('koa');
const app = new Koa();
const json = require('koa-json');
const onerror = require('koa-onerror');
const bodyparser = require('koa-bodyparser');
const logger = require('koa-logger');

const routerMount = require('./startup/router-mount');
const mountApp = require('./startup/index');
//挂载config配置
mountApp(app);
// error handler

onerror(app);
// middlewares
app.use(
    bodyparser({
        enableTypes: ['json', 'form', 'text']
    })
);
app.use(json());
app.use(logger());

app.use(require('koa-static')(__dirname + '/public'));

// routes
routerMount(app);
// error-handling
app.on('error', (err, ctx) => {
    console.error('server error', err, ctx);
});

module.exports = app;
